package com.bawei.fuxi.base.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;

public class GlideUtils {
    private GlideUtils(){}
    private static GlideUtils glideUtils;
    public static GlideUtils getInstance(){
        if(glideUtils == null){
            synchronized (GlideUtils.class){
                if(glideUtils == null){
                    glideUtils = new GlideUtils();
                }
            }
        }
        return glideUtils;
    }

    /**
     * 普通图片
     * @param context
     * @param url
     * @param imageView
     */
    public void loadImage(Context context, String url, ImageView imageView){
        Glide.with(context)
                .load(url)
                .skipMemoryCache(true)//关闭内存缓存
                .transform(new CenterCrop())//剧中裁剪：不留白
                .into(imageView);

    }

    /**
     * 圆形图片
     * @param context
     * @param url
     * @param imageView
     */
    public void loadCircleImage(Context context, String url, ImageView imageView){
        Glide.with(context)
                .load(url)
                .skipMemoryCache(true)//关闭内存缓存
                .transform(new CircleCrop())//圆形裁剪
                .into(imageView);

    }

    /**
     * 圆角图片
     * @param context
     * @param url
     * @param imageView
     * @param raduis 圆角的弧度
     */
    public void loadRoundedImage(Context context, String url, ImageView imageView,int raduis){
        Glide.with(context)
                .load(url)
                .skipMemoryCache(true)//关闭内存缓存
                .transform(new CenterCrop(),new RoundedCorners(raduis))//剧中裁剪：不留白
                .into(imageView);

    }

}
